<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Http\Requests\AuthRequest;
use App\Models\Company;
use Illuminate\Support\Str;

class AuthController extends Controller
{
    public function login(AuthRequest $request) {
    	$company = Company::companyId($request->input('X-Company-Id'))->first();
    	if($company) {
    		$customer = $company->customers()->create(['api_token' => Str::random(64)]);
    	    return response()->json(['token' => $customer->api_token]);
    	}
    	return response()->json(['msg' => 'company not found'], 404);
    }
}
